<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- <script src="index.js">
    </script> -->

    <script>
        function mergeSort(arr, i, j) {
            let mid = Math.floor((i + j) / 2);
            if (i < j) {
                mergeSort(arr, i, mid);
                mergeSort(arr, mid + 1, j);
                merge(arr, i, mid, j);
            }

        }

        function merge(array, i, mid, j) {
            let leftarr = i;
            let rightarr = mid + 1;
            let arr = []
            while (leftarr <= mid && rightarr <= j) {
                if (array[leftarr] < array[rightarr]) {
                    arr.push(array[leftarr++]);
                } else {
                    arr.push(array[rightarr++]);
                }
            }
            while (leftarr <= mid) {
                arr.push(array[leftarr++]);
            }
            while (rightarr <= j) {
                arr.push(array[rightarr++]);
            }
            for (let k = i; k <= j; k++) {
                array[k] = arr[k - i];
            }
        }
        let arr = [1, 2, 3, 142, 142, 3, 14, 24, 32, 21, 0];
        mergeSort(arr, 0, arr.length - 1);
        console.log(arr);
    </script>
</body>

</html>